package com.goods.controller.business;

import com.goods.business.service.ConsumeService;
import com.goods.business.service.OutStockService;
import com.goods.common.model.business.Consumer;
import com.goods.common.model.business.Supplier;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ConsumerVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author XiaoHong
 * @description 物资去处接口
 * @date 2022/2/17
 */
@RestController
@Api(tags = "物资去处接口")
@RequestMapping("/business/consumer")
public class ConsumeController {
    @Autowired
    private ConsumeService consumeService;

    //http://www.localhost:8989/business/consumer/findConsumerList?pageNum=1&pageSize=10&name=
    //获取物资去处列表
    @GetMapping("/findConsumerList")
    public ResponseBean<PageVO<ConsumerVO>> findConsumerList(@RequestParam("pageNum") Integer pageNum,
                                                             @RequestParam("pageSize") Integer pageSize, ConsumerVO consumerVO) {  //实际上传过来的几个过滤条件用实体类接受了；
        System.out.println(consumerVO);
        PageVO<ConsumerVO> inStockVOPageVO = consumeService.findConsumerList(consumerVO, pageNum, pageSize);
        return ResponseBean.success(inStockVOPageVO);
    }

    //    http://www.localhost:8989/consumer/add
    //添加物资去处
    @PostMapping("/add")
    public ResponseBean add(@Validated @RequestBody Consumer consumer) {
        consumeService.add(consumer);
        return ResponseBean.success();
    }

    //点击物资去处修改按钮进行显示指定分类数据
    @GetMapping("/edit/{consumerId}")
    public ResponseBean<Consumer> edit(@PathVariable Long consumerId){
        Consumer consumer = consumeService.edit(consumerId);
        return ResponseBean.success(consumer);
    }

    //http://www.localhost:8989/business/supplier/update/23
    //物资去处编辑界面点击修改确认
    @PutMapping("/update/{consumerId}")
    public ResponseBean update(@RequestBody Consumer consumer,
                               @PathVariable Long consumerId){
        consumeService.update(consumer,consumerId);
        return ResponseBean.success();
    }

    //删除物资去处数据
    @DeleteMapping("/delete/{consumerId}")
    public ResponseBean delete(@PathVariable Long consumerId){
        consumeService.delete(consumerId);
        return ResponseBean.success();
    }

    //获取所有的去向
    @GetMapping("/findAll")
    public ResponseBean<List<Consumer>> findAll(){
        List<Consumer> all = consumeService.findAll();
        return ResponseBean.success(all) ;
    }

}
